package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.BaseInfoAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.presenter.BasicInfoPersenter;
import com.bjesc_b2c.app.appraiset.mvp.presenter.GetCarForPresenter;
import com.bjesc_b2c.app.appraiset.mvp.presenter.impl.BasicInfoPersenterImpl;
import com.bjesc_b2c.app.appraiset.mvp.view.BasicInfoView;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.bjesc_b2c.app.appraiset.utils.LowerCaseToUpperCaseMethod;
import com.bjesc_b2c.app.appraiset.widget.BasePopupWindow;
import com.bjesc_b2c.app.appraiset.widget.dialog.AnalyseDialog;
import com.bjesc_b2c.app.appraiset.widget.dialog.PureTextDialog;
import com.bjesc_b2c.app.appraiset.widget.dialog.SelectTimeDialog;
import com.bjesc_b2c.app.appraiset.widget.dialog.TipDialog;
import com.bjesc_b2c.app.appraiset.widget.layout.FlowRadioGroup;
import com.bjesc_b2c.app.appraiset.widget.popupwindow.BasicDropDownPop;
import com.example.codeutils.utils.FileUtils;
import com.example.codeutils.utils.LogUtils;
import com.example.codeutils.utils.SDCardUtils;
import com.orhanobut.logger.Logger;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import master_bean.BasicInfoBean;
import master_bean.CarForBean;
import rxretrofit_base.model.KeyBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

import static com.bjesc_b2c.app.appraiset.R.id.edit_transfer_num;


/**
 * Created by Jason Chen on 2017/2/21.
 */

public class BasicInfoActivity extends BaseActivity implements BasicInfoView, BasePopupWindow.OnPopupShowOnFinishListener, TipDialog.CallBack,RadioGroup.OnCheckedChangeListener, CompoundButton.OnCheckedChangeListener,MultiItemTypeAdapter.OnItemClickListener{
    //头部
    @InjectView(R.id.iv_arrow)
    ImageView popArrowIv;
    @InjectView(R.id.rlty_more_info)
    RelativeLayout moreInfoRlty;
    //滑动
    @InjectView(R.id.scroll_basic)
    ScrollView scrollerView;
    //文本
    @InjectView(R.id.tv_car_id)
    TextView carIDTv;
    @InjectView(R.id.tv_save_info)
    TextView saveInfoTv;
    @InjectView(R.id.tv_car_for)
    TextView carForTv;
    @InjectView(R.id.tv_car_brand)
    TextView carBrandTv;
    @InjectView(R.id.tv_outfactory_date)
    TextView outFactoryTv;
    @InjectView(R.id.tv_first_upcard)
    TextView firstUpCardTv;
    @InjectView(R.id.tv_car_color)
    TextView carColorTv;
    @InjectView(R.id.tv_compulsory_maturity)
    TextView compulsoryMaturityTv;
    @InjectView(R.id.tv_insurance_maturity)
    TextView insuranceMaturityTv;
    @InjectView(R.id.tv_renewal_expire)
    TextView tv_renewalExpireTv;

    //文本编辑
    @InjectView(R.id.edit_diy_carbrand)
    EditText diyCarBrandEdit;
    @InjectView(R.id.edit_master_phone)
    EditText masterPhoneEdit;
    @InjectView(R.id.edit_car_num)
    EditText carNumEdit;
    @InjectView(R.id.edit_master_name)
    EditText masterNameEdit;
    @InjectView(R.id.edit_master_job)
    EditText masterJobEdit;
    @InjectView(R.id.edit_car_vinnum)
    EditText vinNumEdit;
    @InjectView(edit_transfer_num)
    EditText transferNumEdit;
    @InjectView(R.id.edit_mileage)
    EditText mileageEdit;
    @InjectView(R.id.edit_displacement_num)
    EditText displacementNumEdit;
    @InjectView(R.id.edit_key_num)
    EditText keyNumEdit;
    @InjectView(R.id.edit_insurance_money)
    EditText insuranceMoneyEdit;


    @InjectView(R.id.edit_master_offer)
    EditText masterOfferEdit;
    @InjectView(R.id.edit_floor_price)
    EditText floorPriceEdit;
    @InjectView(R.id.edit_fair)
    EditText fairEdit;

    //单选布局

    @InjectView(R.id.rg_car_license)
    RadioGroup carLicenseRg;
    @InjectView(R.id.rg_registration)
    RadioGroup registrationRg;
    @InjectView(R.id.rg_car_nameplate)
    RadioGroup carNameplateRg;
    @InjectView(R.id.rg_purchase_tax)
    RadioGroup purchaseTaxRg;
    @InjectView(R.id.rg_invoice)
    RadioGroup invoiceRg;
    @InjectView(R.id.rg_maintain_manual)
    RadioGroup maintainManualRg;
    @InjectView(R.id.rg_instructions)
    RadioGroup instructionsRg;
    @InjectView(R.id.rg_mortgage_situation)
    RadioGroup mortgageSituationRg;
    @InjectView(R.id.rg_compulsory)
    RadioGroup compulsoryRg;
    @InjectView(R.id.rg_commercial_insurance)
    RadioGroup commercialInsuranceRg;
    @InjectView(R.id.rg_gearbox)
    RadioGroup gearBoxRg;

    @InjectView(R.id.rg_car_from)
    RadioGroup fromRg;
    @InjectView(R.id.rg_license_plate)
    RadioGroup licensePlateRg;

    @InjectView(R.id.frg_key_type)
    FlowRadioGroup keyTypeFrg;
    @InjectView(R.id.frg_mortgage)
    FlowRadioGroup mortgageFrg;
    @InjectView(R.id.frg_emission_type)
    FlowRadioGroup emissionFrg;
    //布局
    @InjectView(R.id.rlty_compulsory_maturity)
    RelativeLayout compulsoryMaturityRlty;
    @InjectView(R.id.rlty_insurance_maturity)
    RelativeLayout insuranceMaturityRlty;

    @InjectView(R.id.rlty_insurance_money)
    RelativeLayout insuranceMoneyRlty;
    @InjectView(R.id.relative_invoice_price)
    RelativeLayout invoicepriceRlty;

    @InjectView(R.id.recycler_view)
    RecyclerView recyclerView;

    //include
    @InjectView(R.id.include_one)
    View oneIncludeView;
    @InjectView(R.id.include_two)
    View twoIncludeView;
    @InjectView(R.id.lin_scro)
    LinearLayout scroLinear;

    private TipDialog tipDialog;
    private BasicInfoPersenter persenter;
    private PureTextDialog fuelDialog;
    private AnalyseDialog analyseDialog;
    private PureTextDialog selectLabelDialog;
    private SelectTimeDialog compulsoryTimeDialog;
    private SelectTimeDialog outFactoryTimeDialog;
    private SelectTimeDialog firstUpCarTimeDialog;
    private SelectTimeDialog lastTransferTimeDialog;
    private SelectTimeDialog insuranceMaturityDialog;
    private SelectTimeDialog renewalExpireDialog;
    private BasicDropDownPop basicPop;
    private List<CarForBean> carForBean;
    private BasicInfoBean infoBean;
    private GetCarForPresenter carForPresenter;

    private String customName = "";  //自定义车型
    private String masterPhone = ""; //车主电话
    private String carNum = "";      //车牌号码
    private String vinNum = "";      //VIN号码
    private String provinceId = "";      //省份ID
    private String provinceName = "";    //省份名称
    private String cityId = "";          //城市ID
    private String cityName = "";        //城市名称
    private String areaId = "";          //县级ID
    private String areaName = "";        //县级名称
    private String areaAbbreviationName = ""; //最后转入地区简称
    private String outFactoryDate = "";      //出厂日期
    private String firstUpCarDate = "";      //首次上牌时间
    private String lastTransferDate = "";    //最后一次过户时间
    private String fuelType = "";            //燃油类型

    private String colorName = "";           //颜色
    private String label = "";               //标签
    private String area_ProvinceId = "";     //区域省份ID
    private String area_ProvinceName = "";   //区域名称
    private String area_CityId = "";         //区域城市ID
    private String area_CityName = "";       //区域城市名称
    private String area_AreaId = "";         //区域县级ID
    private String area_AreaName = "";       //区域县级名称

    private String carFrom = "";             //来源渠道
    private String carForId = "";              //车辆来源
    private String licensePlate = "";        //牌照
    private String masterName = "";          //车主名
    private String masterJob = "";           //车主职业
    private String saleCause = "";           //卖车原因
    private String checkCarAddressDetail = "";//检车详细地址
    private String transferNum = "";         //过户次数
    private String mileage = "";             //行驶里程
    private String seatNum = "";             //座位数
    private String engineNum = "";           //发动机型号
    private String nowUser = "";             //现在使用方
    private String carryWidget = "";         //随车组件
    private String carryWidgetDescription = "";//随车组件描述
    private String carryTool = "";           //随车工具
    private String uses = "";                //使用性质
    private String maintenanceAddress = "";  //保养地点
    private String isPublish;           //是否发布上架
    private String carLicense = "";          //有无车行证
    private String registration = "";        //登记证
    private String carNameplate = "";        //车身铭牌
    private String purchaseTax = "";         //购置税
    private String invoicec = "";            //发票
    private String invoicecPrice = "";            //发票价
    private String maintenanceManual = "";   //保养手册
    private String instructions = "";        //说明书
    private String keyNum = "";              //钥匙数量
    private String keyType = "";             //钥匙类型
    private String mortgageSituation = "";   //抵押详情
    private String mortgage = "";            //按揭情况
    private String compulsory = "";          //交强险是否过期
    private String compulsoryMaturityDate = "";  //交强险到期时间
    private String renewalExpireDate = "";  //年检到期时间
    private String commercialInsurance = ""; //有无商业险
    private String insuranceMoney = "";      //商业险金额
    private String insuranceMaturityData = "";   //商业险到期时间
    private String gearBox = "";             //变速箱类型
    private String abs = "";                 //abs
    private String carWindow = "";           //车窗类型
    private String seat = "";                //座椅材质
    private String airconditioner = "";      //空调
    private String cruise = "";              //定速导航
    private String wheel = "";               //轮毂
    private String airsac = "";              //气囊
    private String scuttle = "";             //天窗
    private String seatregulate = "";        //座椅调节方式
    private String video = "";              //影音设备
    private String radar = "";               //倒车雷达
    private String turnAssistance = "";      //转向助力
    private String seatFuncation = "";       //座椅功能
    private String rearvieMirror = "";       //后视镜
    private String navigation = "";          //导航
    private String reversingImage = "";      //倒车影像
    private String changeColor = "";         //改色
    private String airAdmission = "";        //进气方式
    private String drive = "";               //驱动方式
    private String spare = "";               //备胎
    private String otherConfig = "";        //其他配置
    private String retrofitting = "";       //加装内容
    private String refit = "";               //是否改装
    private String refitDetails = "";        //改装详情
    private String displacement = "";        //排量
    public static String carSeriesId = "";      //车系ID
    public static String carModelId = "";        //车型ID
    public static String brandId = "";     //车辆品牌ID
    public static String brandName = "";     //品牌名
    public static String carSeriesName = "";//车系名
    public static String carModelName = "";  //车型名
    private String emission = "";           //排放标准
    private BaseInfoAdapter adapter;
    private Intent mIntent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basicinfo_new);
        ButterKnife.inject(this);
        persenter = new BasicInfoPersenterImpl(this);
        initViews();
        tipDialog = new TipDialog(this, this);
    }

    private void initViews() {
        basicPop = new BasicDropDownPop(BasicInfoActivity.this, null);
        basicPop.setShowOnFinishListener(this);
        carLicenseRg.setOnCheckedChangeListener(this);
        registrationRg.setOnCheckedChangeListener(this);
        carNameplateRg.setOnCheckedChangeListener(this);
        purchaseTaxRg.setOnCheckedChangeListener(this);
        invoiceRg.setOnCheckedChangeListener(this);
        maintainManualRg.setOnCheckedChangeListener(this);
        instructionsRg.setOnCheckedChangeListener(this);
        mortgageSituationRg.setOnCheckedChangeListener(this);
        compulsoryRg.setOnCheckedChangeListener(this);
        commercialInsuranceRg.setOnCheckedChangeListener(this);
        gearBoxRg.setOnCheckedChangeListener(this);
        fromRg.setOnCheckedChangeListener(this);
        licensePlateRg.setOnCheckedChangeListener(this);
        keyTypeFrg.setOnCheckedChangeListener(this);
        mortgageFrg.setOnCheckedChangeListener(this);
        emissionFrg.setOnCheckedChangeListener(this);
        vinNumEdit.setTransformationMethod(new LowerCaseToUpperCaseMethod());
        recyclerView.setLayoutManager(new GridLayoutManager(this,4));
        //获取数据
        persenter.getBasicInfo();
    }
    @Override
    protected void onStart() {
        super.onStart();
    }

    @OnClick({R.id.tv_save_info, R.id.rlty_more_info, R.id.rlty_car_brand, R.id.rlty_car_from, R.id.rlty_outfactory_date
            , R.id.rlty_car_color, R.id.tv_vinnum_sort,R.id.btn_post_info
            , R.id.rlty_compulsory_maturity, R.id.rlty_insurance_maturity, R.id.rlty_first_upcard ,R.id.rlty_renewal_expire})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_save_info: //保存
                getAllEditText();
                persenter.saveBasicInfo(saveInfo());
                break;
//            case R.id.rlty_more_info:           //更多
//                setTowardsRightToBottomTextDrawable();
//                basicPop.showAsDropDown(moreInfoRlty);
//                break;
            case R.id.rlty_car_brand:       //车型品牌
                startIntent(new Intent(BasicInfoActivity.this, SelectCarBrandActivity.class), RequestAndResultCode.BasicActivityToSelectCarBrandActivity);
                break;
            case R.id.rlty_car_from:         //车辆来源
                Intent intentCarfo = new Intent(BasicInfoActivity.this, MarketActivity.class);
                intentCarfo.putExtra("TYPE",2);//显示车行
//              intentCarfo.putExtra("CarforList",(Serializable)carForBeanList);
                startIntent(intentCarfo, RequestAndResultCode.BasicActivity_To_CarFromActivity);
                break;
            case R.id.rlty_outfactory_date: //出厂日期
                outFactoryTimeDialog = new SelectTimeDialog(BasicInfoActivity.this, outFactoryListener, false);
                break;
            case R.id.rlty_first_upcard:    //第一次上牌
                firstUpCarTimeDialog = new SelectTimeDialog(BasicInfoActivity.this, firstUpCarListener, false);
                break;
            case R.id.rlty_car_color:       //颜色
                startIntent(new Intent(BasicInfoActivity.this, SelectColorActivity.class), RequestAndResultCode.BasicActivity_To_SelectColorActivity);
                break;
            case R.id.tv_vinnum_sort:       //排重
                if (!TextUtils.isEmpty(vinNumEdit.getText().toString())) {
                    if (vinNumEdit.getText().toString().length() == 17) {
                        analyseDialog = new AnalyseDialog(BasicInfoActivity.this,
                                vinNumEdit.getText().toString(),AnalyseDialog.TYPE_VIN);
                    } else {
                        showToast("VIN号码错误");
                    }
                } else {
                    showToast("VIN号码不能为空");
                }
                break;

            case R.id.rlty_compulsory_maturity:     //交强险到期时间
                compulsoryTimeDialog = new SelectTimeDialog(BasicInfoActivity.this, compulsoryListener, true);
                compulsoryTimeDialog.show();
                break;
            case R.id.rlty_insurance_maturity:     //商业险到期
                insuranceMaturityDialog = new SelectTimeDialog(BasicInfoActivity.this, insuranceMaturityListener, true);
                break;
            case R.id.rlty_renewal_expire:     //年检到期时间
                renewalExpireDialog = new SelectTimeDialog(BasicInfoActivity.this, renewalExpireListener, true);
                break;
            case R.id.btn_post_info:
                putData();

                break;
        }
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        if (mIntent == null){
            mIntent = new Intent(BasicInfoActivity.this,CarSourceActivity.class);
        }
        switch (position){
            case 0:
                mIntent.putExtra("switch",0);
                break;
            case 1:
                mIntent.putExtra("switch",1);
                break;
            case 2:
                mIntent.putExtra("switch",2);
                break;
            case 3:
                mIntent.putExtra("switch",3);
                break;
        }
        startIntent(mIntent,100);
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    private void putData() {
        final String carId = CustomSharedPreferences.getString(this, KeyBean.CARID.valueOf(), KeyBean.FILE_NAME.valueOf());
        HashMap<String, Object> build = new MapUtil()
                .put("id", carId)
                .build();
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(this, build).create(IApiActivityRequest.class).putCar()
                , new BaseSubscriber<TokenBean<CarForBean>>(this) {
                    @Override
                    public void onSuccess(TokenBean<CarForBean> o) {
                        tipDialog.dismiss();

                        if(o.getStatus_code() == 0) {
                            FileUtils.deleteDir(SDCardUtils.getDataPath() + carId);//上传成功清除文件缓存
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {

                    }
                });
    }
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    }

    /**
     * 多选判断
     *
     * @param oneChecked   第一个CheckBox
     * @param twoChecked   第二个CheckBox
     * @param threeChecked 第三个CheckBox
     */
    private String multipleJudgment(CheckBox oneChecked, CheckBox twoChecked, CheckBox threeChecked, CheckBox fourChecked) {
                    String text = "";
                    if (oneChecked.isChecked()) {
                        text = "1";
                        if (twoChecked.isChecked()) {
                            text = "1|2";
                            if (threeChecked.isChecked()) {
                                  text = "1|2|3";
                                if (fourChecked.isChecked()) {
                                    text = "1|2|3|4";
                                }
                            }
                        } else if (threeChecked.isChecked()) {
                            text = "1|3";
                            if (fourChecked.isChecked()) {
                                text = "1|3|4";
                            }
                        } else if (fourChecked.isChecked()) {
                text = "1|4";
            }
        } else if (twoChecked.isChecked()) {
            text = "2";
            if (threeChecked.isChecked()) {
                text = "2|3";
                if (fourChecked.isChecked()) {
                    text = "2|3|4";
                }
            } else if (fourChecked.isChecked()) {
                text = "2|4";
            }
        } else if (threeChecked.isChecked()) {
            text = "3";
            if (fourChecked.isChecked()) {
                text = "3|4";
            }
        } else if (fourChecked.isChecked()) {
            text = "4";
        }
        return text;
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (group.getId()) {
            case R.id.rg_car_from:      //来源渠道
                carFromFuncation(checkedId);
                break;
            case R.id.frg_emission_type:    //排放标准
                emissionFuncation(checkedId);
                break;

            case R.id.rg_car_license:               //行车证
                carLicenseFuncation(checkedId);
                break;
            case R.id.rg_registration:              //登记证
                registrationFuncation(checkedId);
                break;
            case R.id.rg_car_nameplate:             //车身铭牌
                carNameplateFuncation(checkedId);
                break;
            case R.id.rg_purchase_tax:              //购置税收
                purchaseTaxFuncation(checkedId);
                break;
            case R.id.rg_invoice:                   //发票
                invoiceFuncation(checkedId);
                break;
            case R.id.rg_maintain_manual:           //保养手册
                maintainManualFuncation(checkedId);
                break;
            case R.id.rg_instructions:              //说明书
                instructionsFuncation(checkedId);
                break;
            case R.id.frg_key_type:         //钥匙类型
                keyTypeFuncation(checkedId);
                break;
            case R.id.rg_mortgage_situation:        //抵押情况
                mortgageSituationFuncation(checkedId);
                break;
            case R.id.rg_compulsory:                //交强险是否过保
                compulsoryFuncation(checkedId);
                break;
            case R.id.rg_commercial_insurance:      //有无商业险
                commercialInsuranceFuncation(checkedId);
                break;
            case R.id.rg_gearbox:               //变速箱
                gearBoxFuncation(checkedId);
                break;
            case R.id.rg_abs:                   //ABS
                absFuncation(checkedId);
                break;
            case R.id.rg_cruise:                //定速巡航
                cruiseFuncation(checkedId);
                break;
            case R.id.rg_wheel:                 //轮毂
                wheelFuncation(checkedId);
                break;
            case R.id.rg_scuttle:               //天窗
                scuttleFuncation(checkedId);
                break;
            case R.id.rg_seatregulate:          //座椅调节方式
                seatregulateFuncation(checkedId);
                break;
            case R.id.rg_turn_assistance:      //转向助力
                turnAssistanceFuncation(checkedId);
                break;
            case R.id.rg_car_window:            //车窗玻璃
                carWindowFuncation(checkedId);
                break;
            case R.id.rg_reversing_image:       //倒车影像
                reversingImageFuncation(checkedId);
                break;
            case R.id.rg_change_color:          //车辆改色情况
                changeColorFuncation(checkedId);
                break;
            case R.id.rg_air_admission:         //进气方式
                airAdmissionFuncation(checkedId);
                break;
            case R.id.rg_drive:                 //驱动形式
                driveFuncation(checkedId);
                break;
            case R.id.rg_spare:             //备胎
                spareFuncation(checkedId);
                break;
            case R.id.rg_refit:             //改装情况
                refitFuncation(checkedId);
                break;
            case R.id.frg_mortgage:         //按揭情况
                mortgageFuncation(checkedId);
                break;
            case R.id.frg_seat:             //座椅材质
                seatFuncation(checkedId);
                break;
            case R.id.frg_airconditioner:    //空调
                airconditionerFuncation(checkedId);
                break;
            case R.id.frg_video:            //影音设备
                videoFuncation(checkedId);
                break;
            case R.id.frg_radar:            //倒车雷达
                radarFuncation(checkedId);
                break;
            case R.id.frg_navigation:       //导航
                navigationFuncation(checkedId);
                break;
            case R.id.rg_license_plate:     //牌照
                licensePlateFuncation(checkedId);
                break;
        }
    }

    /**
     * 排放标准
     *
     * @param checkedId
     */
    private void emissionFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_emission_two:
                emission = "1";
                break;
            case R.id.rbtn_emission_three:
                emission = "2";
                break;
            case R.id.rbtn_emission_four:
                emission = "3";
                break;
            case R.id.rbtn_emission_five:
                emission = "4";
                break;
        }
    }

    /**
     * 牌照
     *
     * @param checkedId
     */
    private void licensePlateFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_public_brand:             //公牌
                licensePlate = "1";
                break;
            case R.id.rbtn_private_brand:             //私牌
                licensePlate = "2";
                break;
        }
    }

    /**
     * 车辆渠道
     *
     * @param checkedId
     */
    private void carFromFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_car_from_personal:             //个人
                carFrom = "1";
                break;
            case R.id.rbtn_car_from_other:               //渠道
                carFrom = "2";
                break;
        }
    }

    /**
     * 导航
     *
     * @param checkedId
     */
    private void navigationFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_navigation_original: //原装
                navigation = "1";
                break;
            case R.id.rbtn_navigation_not_original: //加装
                navigation = "2";
                break;
            case R.id.rbtn_navigation_not:          //无
                navigation = "3";
                break;
        }
    }

    /**
     * 倒车雷达
     *
     * @param checkedId
     */
    private void radarFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_radar_around:    //前后雷达
                radar = "1";
                break;
            case R.id.rbtn_radar_common:    //普通雷达
                radar = "2";
                break;
            case R.id.rbtn_radar_not:       //无
                radar = "3";
                break;
        }
    }

    /**
     * 影音设备
     *
     * @param checkedId
     */
    private void videoFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_video_radio:     //收音机
                video = "1";
                break;
            case R.id.rbtn_video_cd:        //CD
                video = "2";
                break;
            case R.id.rbtn_video_dvd:       //DVD
                video = "3";
                break;
        }
    }

    /**
     * 空调
     *
     * @param checkedId
     */
    private void airconditionerFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_airconditioner_manual:       //手动控制
                airconditioner = "2";
                break;
            case R.id.rbtn_airconditioner_auto:         //自动空调
                airconditioner = "1";
                break;
            case R.id.rbtn_airconditioner_distinguish:      //温度分区控制
                airconditioner = "3";
                break;
            case R.id.rbtn_airconditioner_around:       //前后空调
                airconditioner = "4";
                break;
        }
    }

    /**
     * 座椅材质
     *
     * @param checkedId
     */
    private void seatFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_corium:
                seat = "1";
                break;
            case R.id.rbtn_imitation:
                seat = "2";
                break;
            case R.id.rbtn_weaving:
                seat = "3";
                break;
        }
    }

    /**
     * 按揭情况
     *
     * @param checkedId
     */
    private void mortgageFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_mortgage_not:        //无按揭
                mortgage = "1";
                break;
            case R.id.rbtn_already_settled_notcard: //已还清，未拿证
                mortgage = "2";
                break;
            case R.id.rbtn_not_settled_buyerrepay:  //未还清，买方还
                mortgage = "4";
                break;
            case R.id.rbtn_not_settled_sellerrepay: //未还清，卖方还
                mortgage = "3";
                break;
        }
    }

    /**
     * 钥匙类型
     *
     * @param checkedId
     */
    private void keyTypeFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_key_ordinary:        //普通
                keyType = "1";
                break;
            case R.id.rbtn_key_remote_control:      //遥控
                keyType = "2";
                break;
            case R.id.rbtn_key_onekey:      //一键启动
                keyType = "3";
                break;
            case R.id.rbtn_key_not:         //无钥匙进入
                keyType = "4";
                break;
        }
    }



    /**
     * 改装情况
     *
     * @param checkedId
     */
    private void refitFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_refit_exist:     //有
                refit = "1";

                scrollHandler.sendMessage(scrollHandler.obtainMessage());
                break;
            case R.id.rbtn_refit_not:       //无
                refit = "2";
                break;
        }
    }

    /**
     * 备胎
     *
     * @param checkedId
     */
    private void spareFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_spare_exist: //有
                spare = "1";
                break;
            case R.id.rbtn_spare_not:   //无
                spare = "2";
                break;
        }
    }

    /**
     * 驱动形式
     *
     * @param checkedId
     */
    private void driveFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_drive_two:       //两驱
                drive = "1";
                break;
            case R.id.rbtn_drive_four:      //四驱
                drive = "2";
                break;

        }
    }

    /**
     * 进气方式
     *
     * @param checkedId
     */
    private void airAdmissionFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_air_admission_nature:    //自然吸气
                airAdmission = "1";
                break;
            case R.id.rbtn_air_admission_turbocharging:     //涡轮增压
                airAdmission = "2";
                break;
        }
    }

    /**
     * 车辆改色
     *
     * @param checkedId
     */
    private void changeColorFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_change_color_yes:    //有
                changeColor = "1";
                break;
            case R.id.rbtn_change_color_not:    //无
                changeColor = "2";
                break;

        }
    }

    /**
     * 倒车影像
     *
     * @param checkedId
     */
    private void reversingImageFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_reversing_image_exist:       //有
                reversingImage = "1";
                break;
            case R.id.rbtn_reversing_image_not:         //无
                reversingImage = "2";
                break;
        }
    }

    /**
     * 车窗
     *
     * @param checkedId
     */
    private void carWindowFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_car_window_not:       //无
                carWindow = "1";
                break;
            case R.id.rbtn_car_window_two:     //2个门
                carWindow = "2";
                break;
            case R.id.rbtn_car_window_four:     //4个门
                carWindow = "3";
                break;
        }
    }

    /**
     * 转向助力
     *
     * @param checkedId
     */
    private void turnAssistanceFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_turn_assistance_exist:       //有
                turnAssistance = "1";
                break;
            case R.id.rbtn_turn_assistance_not:         //无
                turnAssistance = "2";
                break;
        }
    }

    /**
     * 座椅调节方式
     *
     * @param checkedId
     */
    private void seatregulateFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_seatregulate_manual:     //手动
                seatregulate = "2";
                break;
            case R.id.rbtn_seatregulate_electric:   //电动
                seatregulate = "1";
                break;
        }
    }

    /**
     * 天窗
     *
     * @param checkedId
     */
    private void scuttleFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_scuttle_ordinary:       //普通
                scuttle = "1";
                break;
            case R.id.rbtn_scuttle_panoramic:         //全景
                scuttle = "2";
                break;
            case R.id.rbtn_scuttle_not:             //无
                scuttle = "3";
                break;
        }
    }

    /**
     * 轮毂
     *
     * @param checkedId
     */
    private void wheelFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_wheel_aluminium_alloy:       //铝合金
                wheel = "1";
                break;
            case R.id.rbtn_wheel_steel:                 //铁钢圈
                wheel = "2";
                break;
        }
    }

    /**
     * 定速巡航
     *
     * @param checkedId
     */
    private void cruiseFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_cruise_exist:        //有
                cruise = "1";
                break;
            case R.id.rbtn_cruise_not:          //无
                cruise = "2";
                break;
        }
    }

    /**
     * ABS
     *
     * @param checkedId
     */
    private void absFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_abs_exist:   //有
                abs = "1";
                break;
            case R.id.rbtn_abs_not:     //无
                abs = "2";
                break;
        }
    }

    /**
     * 变速箱
     *
     * @param checkedId
     */
    private void gearBoxFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_mt:      //MT变速箱
                gearBox = "2";
                break;
            case R.id.rbtn_at:      //AT变速箱
                gearBox = "1";
                break;
        }
    }

    /**
     * 有无商业险
     *
     * @param checkedId
     */
    private void commercialInsuranceFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_commercial_insurance_exist:      //有
                commercialInsurance = "1";
                insuranceMoneyEdit.setVisibility(View.VISIBLE);
                insuranceMaturityRlty.setVisibility(View.VISIBLE);
                insuranceMoneyRlty.setVisibility(View.VISIBLE);
                scrollHandler.sendMessage(scrollHandler.obtainMessage());
                break;
            case R.id.rbtn_commercial_insurance_not:        //无
                commercialInsurance = "2";
                insuranceMoneyEdit.setVisibility(View.GONE);
                insuranceMaturityRlty.setVisibility(View.GONE);
                insuranceMoneyRlty.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 交强险是否过保
     *
     * @param checkedId
     */
    private void compulsoryFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_compulsory_exist:    //未过保
                compulsory = "2";
                compulsoryMaturityRlty.setVisibility(View.VISIBLE);
                findViewById(R.id.line_1_two).setVisibility(View.GONE);
                findViewById(R.id.line_2_two).setVisibility(View.VISIBLE);
                break;
            case R.id.rbtn_compulsory_not:      //已过保
                compulsory = "1";
                compulsoryMaturityRlty.setVisibility(View.GONE);
                findViewById(R.id.line_1_two).setVisibility(View.VISIBLE);
                findViewById(R.id.line_2_two).setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 抵押情况
     *
     * @param checkedId
     */
    private void mortgageSituationFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_mortgage_situation_exist:    //有
                mortgageSituation = "1";
                break;
            case R.id.rbtn_mortgage_situation_not:      //无
                mortgageSituation = "2";
                break;
        }
    }

    /**
     * 说明书
     *
     * @param checkedId
     */
    private void instructionsFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_instructions_exist:  //有
                instructions = "1";
                break;
            case R.id.rbtn_instructions_not:    //无
                instructions = "2";
                break;
        }
    }

    /**
     * 保养手册
     *
     * @param checkedId
     */
    private void maintainManualFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_maintain_manual_exist:   //有
                maintenanceManual = "1";
                break;
            case R.id.rbtn_maintain_manual_not:     //无
                maintenanceManual = "2";
                break;
        }
    }

    /**
     * 发票
     *
     * @param checkedId
     */
    private void invoiceFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_invoice_exist:       //有
                invoicec = "1";
                invoicepriceRlty.setVisibility(View.VISIBLE);
                break;
            case R.id.rbtn_invoice_not:         //无
                invoicec = "2";
                invoicecPrice="";
                invoicepriceRlty.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 购置税收
     *
     * @param checkedId
     */
    private void purchaseTaxFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_purchase_exist:      //有
                purchaseTax = "1";
                break;
            case R.id.rbtn_purchase_not:        //无
                purchaseTax = "2";
                break;
        }
    }

    /**
     * 车身铭牌
     *
     * @param checkedId
     */
    private void carNameplateFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_car_nameplate_exist: //有
                carNameplate = "1";
                break;
            case R.id.rbtn_car_nameplate_not:   //无
                carNameplate = "2";
                break;
        }
    }


    /**
     * 登记证
     *
     * @param checkedId
     */
    private void registrationFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_registration_exist:  //有
                registration = "1";
                break;
            case R.id.rbtn_registration_not:    //无
                registration = "2";
                break;
        }
    }

    /**
     * 行车证
     *
     * @param checkedId
     */
    private void carLicenseFuncation(int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_car_license_exist:       //有
                carLicense = "1";
                break;
            case R.id.rbtn_car_license_not:         //无
                carLicense = "2";
                break;
        }
    }



    /**
     * 交强险到期
     */
    private SelectTimeDialog.OnSelectTimeListener compulsoryListener = new SelectTimeDialog.OnSelectTimeListener() {
        @Override
        public void onSelectTime(String year, String month, String day) {
            compulsoryMaturityDate = year + "-" + month + "-" + day;
            compulsoryMaturityTv.setText(compulsoryMaturityDate);
        }
    };

    /**
     * 商业险到期
     */
    private SelectTimeDialog.OnSelectTimeListener insuranceMaturityListener = new SelectTimeDialog.OnSelectTimeListener() {
        @Override
        public void onSelectTime(String year, String month, String day) {
            insuranceMaturityData = year + "-" + month + "-" + day;
            insuranceMaturityTv.setText(insuranceMaturityData);
        }
    };
    /**
     * 年检到期
     */
    private SelectTimeDialog.OnSelectTimeListener renewalExpireListener = new SelectTimeDialog.OnSelectTimeListener() {
        @Override
        public void onSelectTime(String year, String month, String day) {
            renewalExpireDate = year + "-" + month + "-" + day;
            tv_renewalExpireTv.setText(renewalExpireDate);
        }
    };
    /**
     * 出厂日期
     */
    private SelectTimeDialog.OnSelectTimeListener outFactoryListener = new SelectTimeDialog.OnSelectTimeListener() {
        @Override
        public void onSelectTime(String year, String month, String day) {
            outFactoryDate = year + "-" + month + "-" + day;
            outFactoryTv.setText(outFactoryDate);
        }
    };

    /**
     * 首次上牌
     */
    private SelectTimeDialog.OnSelectTimeListener firstUpCarListener = new SelectTimeDialog.OnSelectTimeListener() {
        @Override
        public void onSelectTime(String year, String month, String day) {
            firstUpCarDate = year + "-" + month + "-" + day;
            firstUpCardTv.setText(firstUpCarDate);
        }
    };



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode) {
            case RequestAndResultCode.SelectColorActivity_ResultCode:   //颜色选择
                colorName = data.getStringExtra("colorName");
                carColorTv.setText(colorName);
                break;
            case RequestAndResultCode.CarFromActivity_ResultCode:  //车辆来源
                carForId = data.getStringExtra("carFofId");
                Logger.d("RequestAndResultCode"+ carForId);
                if (!TextUtils.isEmpty(data.getStringExtra("carForName"))) {
                    carForTv.setText(data.getStringExtra("carForName"));
                }
                break;
            case RequestAndResultCode.SelectCarBrandActivity_ResultCode:  //车辆品牌

                carBrandTv.setText(brandName + carSeriesName + carModelName);
                break;
            case 101://刷新界面
                persenter.getBasicInfo();
                break;
        }

    }


    /**
     * 箭头动画，左转下
     */
    private void setTowardsRightToBottomTextDrawable() {
        ObjectAnimator oa = ObjectAnimator.ofFloat(popArrowIv, "rotation", 0f, 90f);
        oa.setDuration(200);
        oa.start();
    }

    /**
     * 箭头动画，下转左
     */
    private void setTowardsBottomToRightTextDrawable() {
        ObjectAnimator oa = ObjectAnimator.ofFloat(popArrowIv, "rotation", 90f, 0f);
        oa.setDuration(200);
        oa.start();
    }

    /**
     * 箭头动画，上转下
     */
    private void setTowardsTopToBottomTextDrawable(View view) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(view, "rotation", 0f, 180f);
        oa.setDuration(200);
        oa.start();
    }

    /**
     * 箭头动画，下转上
     */
    private void setTowardsBottomToTopTextDrawable(View view) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(view, "rotation", 180f, 0f);
        oa.setDuration(200);
        oa.start();
    }

    /**
     * 设置车辆信息、手续信息、配置信息点击后的背景颜色为灰色
     *
     * @param v
     */
    private void changeBackgroundToGray(View v) {
        v.setBackgroundResource(R.color.bg);
    }

    /**
     * 设置车辆信息、手续信息、配置信息点击后的背景颜色为白色
     *
     * @param v
     */
    private void changeBackgroundToWhite(View v) {
        v.setBackgroundResource(R.color.colorWhite);
    }


    @Override
    public void onFinish() {
        setTowardsBottomToRightTextDrawable();
    }

    @Override
    public void onShow() {

    }

    private Handler scrollHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            scrollerView.fullScroll(View.FOCUS_DOWN);
            return false;
        }
    });

    /**
     * 获取基本信息，并设置
     *
     * @param bean
     */
    @Override
    public void getBasicInfo(BasicInfoBean bean) {
        infoBean = bean;
        if (adapter == null){
            adapter = new BaseInfoAdapter(BasicInfoActivity.this,R.layout.layout_item_baseinfo_recly,bean.getImgs());
            adapter.setOnItemClickListener(this);
            recyclerView.setAdapter(adapter);
        }else{
            adapter.refresh(bean.getImgs());
        }
        carIDTv.setText("车源ID : " + CustomSharedPreferences.getString(this, KeyBean.CARID.valueOf(), KeyBean.FILE_NAME.valueOf()));
        //车源ID
        //车辆信息
        if (!TextUtils.isEmpty(bean.getBrand_name())) {   //车源品牌名
            brandName = bean.getBrand_name();
        }else {
            brandName = "";
        }
        if (!TextUtils.isEmpty(bean.getBrand_id())) {   //车源品牌ID
            brandId = bean.getBrand_id();
        }else{
            brandId = "";
        }
        if (!TextUtils.isEmpty(bean.getCarserie_name())) {   //车系名
           carSeriesName = bean.getCarserie_name();
        }else{
            carSeriesName = "";
        }
        if (!TextUtils.isEmpty(bean.getCarserie_id())) {   //车系ID
            carSeriesId = bean.getCarserie_id();
        }else{
            carSeriesId = "";
        }
        if (!TextUtils.isEmpty(bean.getCarspec_name())) {   //车型名
            carModelName = bean.getCarspec_name();
        }else{
            carModelName = "";
        }
        if (!TextUtils.isEmpty(bean.getCarspec_id())) {   //车型ID
            carModelId = bean.getCarspec_id();
        }else{
            carModelId = "";
        }
        String bcc = brandName + carSeriesName + carModelName;
        if(!TextUtils.isEmpty(bcc)){
            carBrandTv.setText(bcc);//车品牌+系列+型号
        }

        if (!TextUtils.isEmpty(bean.getCar_model()) && !bean.getCar_model().equals("0")) {   //自定义车型
            customName = bean.getCar_model();
            LogUtils.e(customName.toString());
            diyCarBrandEdit.setText(customName);
        }

        if (!TextUtils.isEmpty(bean.getMobile())) {   //车主电话
            masterPhone = bean.getMobile();
            masterPhoneEdit.setText(masterPhone);
        }
        if (!TextUtils.isEmpty(bean.getPlate_number())) {   //车牌号码
            carNum = bean.getPlate_number();
            carNumEdit.setText(carNum);
        }

        if (!TextUtils.isEmpty(bean.getPlate_type())) {   //    牌照
            licensePlate = bean.getPlate_type();
            if (licensePlate.equals("1")) {     //无法封装
                ((RadioButton) licensePlateRg.getChildAt(0)).setChecked(true);
            } else if (licensePlate.equals("2")) {
                ((RadioButton) licensePlateRg.getChildAt(1)).setChecked(true);
            }
        }
        if (!TextUtils.isEmpty(bean.getOwner_price())) {
            masterOfferEdit.setText(bean.getOwner_price());
        }
        if (!TextUtils.isEmpty(bean.getFair_price())) {
            fairEdit.setText(bean.getFair_price());
        }
        if (!TextUtils.isEmpty(bean.getLow_price())) {
            floorPriceEdit.setText(bean.getLow_price());
        }
        if (!TextUtils.isEmpty(bean.getVin_number())) {   //    VIN码
            vinNum = bean.getVin_number();
            vinNumEdit.setText(vinNum);
        }
        if (!TextUtils.isEmpty(bean.getSource_type())) {   //来源渠道
            carFrom = bean.getSource_type();
            setRadioButtonSelect(carFrom, fromRg);
        }
        if (!TextUtils.isEmpty(bean.getSource())) {   //车辆来源
            carForId = bean.getSource();
            Logger.d("车辆来源"+ carForId);
        }
        if (!TextUtils.isEmpty(bean.getDealer_name())) {   //车辆来源
            carForTv.setText(bean.getDealer_name());
        }

        if (!TextUtils.isEmpty(bean.getOwner_name()))

        {   //车主名
            masterName = bean.getOwner_name();
            masterNameEdit.setText(masterName);
        }

        if (!TextUtils.isEmpty(bean.getOwner_careers()))

        {   //车主职业
            masterJob = bean.getOwner_careers();
            masterJobEdit.setText(masterJob);
        }

        if (!TextUtils.isEmpty(bean.getCheck_province()))

        {   //检车省份名
            provinceName = bean.getCheck_province();
        }

        if (!TextUtils.isEmpty(bean.getCheck_province_id()))

        {   //检车省份ID
            provinceId = bean.getCheck_province_id();
        }

        if (!TextUtils.isEmpty(bean.getCheck_city()))

        {   //    检车城市名
            cityName = bean.getCheck_city();
        }

        if (!TextUtils.isEmpty(bean.getCheck_city_id()))

        {   //检车城市ID
            cityId = bean.getCheck_city_id();
        }

        if (!TextUtils.isEmpty(bean.getCheck_area()))

        {   //    检车县级名
            areaName = bean.getCheck_area();
        }

        if (!TextUtils.isEmpty(bean.getProduction_time()))

        {   //出厂日期
            outFactoryDate = bean.getProduction_time();
            outFactoryTv.setText(outFactoryDate);
        }

        if (!TextUtils.isEmpty(bean.getLicense_time()))

        {   //首次上牌日期
            firstUpCarDate = bean.getLicense_time();
            firstUpCardTv.setText(firstUpCarDate);
        }

        if (!TextUtils.isEmpty(bean.getTransfer_num()))

        {   //过户次数
            transferNum = bean.getTransfer_num();
            transferNumEdit.setText(transferNum);
        }


        if (!TextUtils.isEmpty(bean.getBrand_name()))

        {   //行驶里程
            mileage = bean.getTravel_mileage();
            mileageEdit.setText(mileage);
        }

        if (!TextUtils.isEmpty(bean.getDisplacement()))

        {   //排量
            displacement = bean.getDisplacement();
            displacementNumEdit.setText(displacement);
        }

        if (!TextUtils.isEmpty(bean.getCar_color())) {   //颜色
            colorName = bean.getCar_color();
            carColorTv.setText(colorName);
        }

        //手续信息
        if (!TextUtils.isEmpty(bean.getIs_vehicle_passport())) {   //行车证
            carLicense = bean.getIs_vehicle_passport();
            setRadioButtonSelect(carLicense, carLicenseRg);
        }

        if (!TextUtils.isEmpty(bean.getRegistration())) {   // 登记证
            registration = bean.getRegistration();
            setRadioButtonSelect(registration, registrationRg);
        }

        if (!TextUtils.isEmpty(bean.getCar_nameplate())) {   //车身铭牌
            carNameplate = bean.getCar_nameplate();
            setRadioButtonSelect(carNameplate, carNameplateRg);
        }

        if (!TextUtils.isEmpty(bean.getPurchase_tax())) {   //购置税收
            purchaseTax = bean.getPurchase_tax();
            setRadioButtonSelect(purchaseTax, purchaseTaxRg);
        }

        if (!TextUtils.isEmpty(bean.getBuy_invoicec())) {   //发票
            invoicec = bean.getBuy_invoicec();
            setRadioButtonSelect(invoicec, invoiceRg);
        }
        if (!TextUtils.isEmpty(bean.getInvoice_price())) {   //发票价
            invoicecPrice = bean.getInvoice_price();
            Logger.d("发票价格>>>>>>"+invoicecPrice);
        }
        if (!TextUtils.isEmpty(bean.getMaintenance_manual())) {   //保养手册
            maintenanceManual = bean.getMaintenance_manual();
            setRadioButtonSelect(maintenanceManual, maintainManualRg);
        }

        if (!TextUtils.isEmpty(bean.getInstructions())) {   //说明书
            instructions = bean.getInstructions();
            setRadioButtonSelect(instructions, instructionsRg);
        }

        if (!TextUtils.isEmpty(bean.getKey_num())) {   //钥匙数量
            keyNum = bean.getKey_num();
            keyNumEdit.setText(keyNum);
        }

        if (!TextUtils.isEmpty(bean.getKey_type())) {   //钥匙类型
            keyType = bean.getKey_type();
            setRadioButtonSelect(keyType, keyTypeFrg);
        }

        if (!TextUtils.isEmpty(bean.getPledge())) {   //抵押情况
            mortgageSituation = bean.getPledge();
            setRadioButtonSelect(mortgageSituation, mortgageSituationRg);
        }

        if (!TextUtils.isEmpty(bean.getMortgage())) {   //按揭情况
            mortgage = bean.getMortgage();
            if (mortgage.equals("1")) {     //不能封装
                ((RadioButton) mortgageFrg.getChildAt(0)).setChecked(true);
            } else if (mortgage.equals("2")) {
                ((RadioButton) mortgageFrg.getChildAt(1)).setChecked(true);
            } else if (mortgage.equals("4")) {
                ((RadioButton) mortgageFrg.getChildAt(2)).setChecked(true);
            } else if (mortgage.equals("3")) {
                ((RadioButton) mortgageFrg.getChildAt(3)).setChecked(true);
            }
        }

        if (!TextUtils.isEmpty(bean.getAfter_warranty())) {   //交强险是否过保
            compulsory = bean.getAfter_warranty();
            if (compulsory.equals("2")) { //未过保       //不能封装
                ((RadioButton) compulsoryRg.getChildAt(0)).setChecked(true);
            } else if (compulsory.equals("1")) {//已过保
                ((RadioButton) compulsoryRg.getChildAt(1)).setChecked(true);
            }
        }

        if (!TextUtils.isEmpty(bean.getCompulsory_insurance_expire()))

        {   //交强险到期时间
            compulsoryMaturityDate = bean.getCompulsory_insurance_expire();
            compulsoryMaturityTv.setText(compulsoryMaturityDate);
        }

        if (!TextUtils.isEmpty(bean.getCommercial_insurance()))

        {   //有无商业险
            commercialInsurance = bean.getCommercial_insurance();
            setRadioButtonSelect(commercialInsurance, commercialInsuranceRg);
        }

        if (!TextUtils.isEmpty(bean.getCommercial_insurance_price()))

        {   //商业险金额
            insuranceMoney = bean.getCommercial_insurance_price();
            insuranceMoneyEdit.setText(insuranceMoney);
        }

        if (!TextUtils.isEmpty(bean.getCommercial_insurance_expire()))

        {   //商业险到期时间
            insuranceMaturityData = bean.getCommercial_insurance_expire();
            insuranceMaturityTv.setText(insuranceMaturityData);
        }
        if (!TextUtils.isEmpty(bean.getRenewal_expire()))

        {   //年检到期时间
            renewalExpireDate = bean.getRenewal_expire();
            tv_renewalExpireTv.setText(renewalExpireDate);
        }

        //配置信息
        if (!TextUtils.isEmpty(bean.getGearbox()))

        {   //变速箱
            gearBox = bean.getGearbox();
            if (gearBox.equals("2")) {  //MT      //无法封装
                ((RadioButton) gearBoxRg.getChildAt(0)).setChecked(true);
            } else if (gearBox.equals("1")) {  //AT
                ((RadioButton) gearBoxRg.getChildAt(1)).setChecked(true);
            }
        }

        if (!TextUtils.isEmpty(bean.getAir_conditioner()))

        {   //空调
            airconditioner = bean.getAir_conditioner();
        }

        if (!TextUtils.isEmpty(bean.getGasbug()))

        {   //气囊
            airsac = bean.getGasbug();
        }
        if (!TextUtils.isEmpty(bean.getModification_desc()))

        {   //改装详情
            refitDetails = bean.getModification_desc();
        }

        if (!TextUtils.isEmpty(bean.getEmission_standard()))

        {
            emission = bean.getEmission_standard();
            setRadioButtonSelect(emission, emissionFrg);
        }
    }

    private void getAllEditText() {
        //自定义车型
        customName = diyCarBrandEdit.getText().toString();
        masterPhone = masterPhoneEdit.getText().toString();
        carNum = carNumEdit.getText().toString();
        vinNum = vinNumEdit.getText().toString();
        masterName = masterNameEdit.getText().toString();
        masterJob = masterJobEdit.getText().toString();
        transferNum = transferNumEdit.getText().toString();
        mileage = mileageEdit.getText().toString();
        displacement = displacementNumEdit.getText().toString();
        keyNum = keyNumEdit.getText().toString();
        insuranceMoney = insuranceMoneyEdit.getText().toString();
    }

    /**
     * 保存数据到对象
     */
    public BasicInfoBean saveInfo() {
        if (infoBean == null) {
            infoBean = new BasicInfoBean();
        }
        //车辆信息
        infoBean.setId(CustomSharedPreferences.getString(this, KeyBean.CARID.valueOf(), KeyBean.FILE_NAME.valueOf()));//保存ID
        infoBean.setCar_model(customName);  //定义车型
        infoBean.setBrand_id(brandId);      //品牌ID
        Logger.d("brandId==="+brandId);
        infoBean.setCarserie_id(carSeriesId);  //自定义车型
        infoBean.setCarspec_id(carModelId); //自定义车型
        infoBean.setMobile(masterPhone);    //车主电话
        infoBean.setPlate_number(carNum);   //车牌
        infoBean.setPlate_type(licensePlate);//公私牌
        infoBean.setVin_number(vinNum);     //VIN
        infoBean.setSource_type(carFrom);   //来源渠道
        infoBean.setSource(carForId);       //车辆来源 29代表车行车市 固定格式
        infoBean.setOwner_name(masterName); //车主名
        infoBean.setOwner_careers(masterJob);//车主职业
        infoBean.setSell_car_causes(saleCause);      //卖车原因
        infoBean.setCheck_province_id(provinceId);//检车省份ID
        infoBean.setCheck_city_id(cityId);      //检车城市ID
        infoBean.setCheck_area_id(areaId);      //检车县级ID
        infoBean.setSpecific_address(checkCarAddressDetail);//检车详情地址
        infoBean.setProduction_time(outFactoryDate);//出厂日期
        infoBean.setLicense_time(firstUpCarDate);//首次上牌日期
        infoBean.setTransfer_num(transferNum);  //过户次数
        infoBean.setTransfer_time(lastTransferDate);//最后过户时间
        infoBean.setTravel_mileage(mileage);    //行驶里程
        infoBean.setEmission_standard(emission);    //排放标准
        infoBean.setLast_province(areaAbbreviationName);//最后转入地
        infoBean.setSeat_num(seatNum);      //座位数
        infoBean.setDisplacement(displacement);//排量
        infoBean.setMotor_no(engineNum);    //发动机型号
        infoBean.setUser_person(nowUser);   //使用方
        infoBean.setFuel_oil(fuelType);     //燃油类型
        infoBean.setCar_assembly(carryWidget);//随车组件
        infoBean.setAssembly_desc(carryWidgetDescription);//随车组件描述
        infoBean.setCar_tool(carryTool);    //随车工具
        infoBean.setCar_color(colorName);   //颜色
        infoBean.setUse_property(uses);     //使用性质
        infoBean.setMaintain_place(maintenanceAddress);       //保养地点
        infoBean.setTags(label);            //标签
        infoBean.setSee_car_province_id(area_ProvinceId);   //选择区域省份
        infoBean.setSee_car_city_id(area_CityId);           //选择区域城市
        infoBean.setSee_car_area_id(area_AreaId);           //选择区域县级
        infoBean.setOwner_price(masterOfferEdit.getText().toString());
        infoBean.setLow_price(floorPriceEdit.getText().toString());
        infoBean.setFair_price(fairEdit.getText().toString());
        //手续信息
        infoBean.setIs_vehicle_passport(carLicense);   //行车证
        infoBean.setRegistration(registration);        //登记证
        infoBean.setCar_nameplate(carNameplate);        //车身铭牌
        infoBean.setPurchase_tax(purchaseTax);          //购置税
        infoBean.setBuy_invoicec(invoicec);             //发票
        infoBean.setInvoice_price(invoicecPrice);       //发票价
        infoBean.setMaintenance_manual(maintenanceManual);//保养手册
        infoBean.setInstructions(instructions);         //说明书
        infoBean.setKey_num(keyNum);                    //钥匙数量
        infoBean.setKey_type(keyType);                  //钥匙类型
        infoBean.setPledge(mortgageSituation);       //抵押情况
        infoBean.setMortgage(mortgage);              //按揭情况
        infoBean.setAfter_warranty(compulsory);       //交强险
        infoBean.setCompulsory_insurance_expire(compulsoryMaturityDate);      //交强险到期时间
        infoBean.setCommercial_insurance(commercialInsurance);     //有无商业险
        infoBean.setCommercial_insurance_price(insuranceMoney);     //商业险金额
        infoBean.setCommercial_insurance_expire(insuranceMaturityData);        //商业险到期时间
        infoBean.setRenewal_expire(renewalExpireDate);//年检到期时间

        //配置信息
        infoBean.setGearbox(gearBox);       //变速箱
        infoBean.setAbs(abs);               //ABS
        infoBean.setWindow_glass(carWindow);//车窗
        infoBean.setSeat_material(seat);    //座椅材质
        infoBean.setAir_conditioner(airconditioner);//空调
        infoBean.setCruise_control(cruise); //定速巡航
        infoBean.setHub(wheel);      //轮毂
        infoBean.setSkylight(scuttle);//天窗
        infoBean.setSeat_method(seatregulate);//座椅调节方式
        infoBean.setMusic_equipment(video); //影音设备
        infoBean.setReverse_sensor(radar);       //倒车雷达
        infoBean.setSteering_booster(turnAssistance);     //转向助力
        infoBean.setExterior_mirror(rearvieMirror);      //后视镜
        infoBean.setSeat_function(seatFuncation);   //座椅功能
        infoBean.setGasbug(airsac);   //座椅功能
        infoBean.setNavigation(navigation);     //导航
        infoBean.setReverse_image(reversingImage);  //倒车影像
        infoBean.setChange_color(changeColor);  //改色
        infoBean.setAir_type(airAdmission);                 //进气方式
        infoBean.setDrive_type(drive);          //驱动方式
        infoBean.setSpare_tire(spare);      //备胎
        infoBean.setOriginal_binding(otherConfig);//其他配置
        infoBean.setInstallation_configuration(retrofitting);//加装
        infoBean.setModification_situation(refit);   //改装情况
        infoBean.setModification_desc(refitDetails);    //改装详情
        return infoBean;
    }

    private void setCheckBoxSelect(String text, CheckBox boxOne, CheckBox boxTwo, CheckBox boxThree, CheckBox boxFour) {
        String[] rearvieMirrorSplit = text.split("\\|");
        if (rearvieMirrorSplit != null && rearvieMirrorSplit.length > 0) {
            for (int i = 0; i < rearvieMirrorSplit.length; i++) {
                if (rearvieMirrorSplit[i].equals("1")) {
                    boxOne.setChecked(true);
                } else if (rearvieMirrorSplit[i].equals("2")) {
                    boxTwo.setChecked(true);
                } else if (rearvieMirrorSplit[i].equals("3")) {
                    boxThree.setChecked(true);
                } else if (rearvieMirrorSplit[i].equals("0")) {
                    boxFour.setChecked(true);
                }
            }
        }
    }

    /**
     * 设置单选按钮
     *
     * @param text
     * @param group
     */
    private void setRadioButtonSelect(String text, RadioGroup group) {
        if (text.equals("1")) {
            ((RadioButton) group.getChildAt(0)).setChecked(true);
        } else if (text.equals("2")) {
            ((RadioButton) group.getChildAt(1)).setChecked(true);
        } else if (text.equals("3")) {
            ((RadioButton) group.getChildAt(2)).setChecked(true);
        } else if (text.equals("4")) {
            ((RadioButton) group.getChildAt(3)).setChecked(true);
        }
    }

    @Override
    public void callBack() {

    }

    @Override
    public void onBackPressed() {
        saveInfo();
        finish();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
           carSeriesId = null;      //车系ID
           carModelId = null;        //车型ID
           brandId = null;     //车辆品牌ID
           brandName = null;     //品牌名
           carSeriesName = null;//车系名
           carModelName = null;  //车型名
    }
}
